No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
Introduction
------------
Ever wanted to keep track of the number of calls you've received while you were out? You might have an answering machine connected to your phone line, but it might not record the time a call came in. This hack will keep track of the number of calls that come in and display the time they arrive.
To perform this hack, we set MicroPhone to listen to the modem on the serial port. We wait for the "RING" response from the modem, indicating that a call is coming in. When we see this message, we compute the time and day and display the information. Then, we wait until another call comes through.
Instructions - Put the module called 'LineListener' in your Module Folder, which is in the same location as the MicroPhone application. If you do not have a Module Folder, create one. Open any MicroPhone settings document. Create the following script:
Do Script "'Main','LineListener'"
That's it.
Theory
------
So, what's behind this hack? Let's take a quick look at the scripts in LineListener. Here are the scripts in the LineListener module:
GetDate
Main
LineListener
GetDate - this script takes the current date and time and formats it to look like this: "931010 - 14:55", which would translate to 2:55 PM on October 10, 1993. It stores this formatted date in the variable called "GetDate".
Main - this script simply calls the script LineListener. It is used to provide a single entry point into the module. This way, you don't have to know the name of a particular script. Just call the main script in any of the modules that have been provided with Open Mike and they will do the right thing.
LineListener - This script does the work of initializing the modem and listening to the line. Let's take a look at it:
Send Text String "'ATE1QV1S0=0^M {to prevent modem from picking up}'"
Set Variable * ll_done from Expression "false"
Repeat
When Button "'Stop', 27064 {stop sign icon}"
Remark "--- we'll stop listening to the line"
Set Variable * ll_done from Expression "true"
Or When Expression "ASCII(NextKey) = 27 {escape character}"
Remark "--- we'll stop listening to the line"
Set Variable * ll_done from Expression "true"
Or When Text in Stream is "'RING'"
Wait Sixtieths "30 {to allow cursor to go to next line}"
Do Script * "'GetDate'"
Send Local to Screen "GetDate & ' (incoming call detected)^M^J'"
When Silence is "60 * 10 {wait for 10 seconds of silence}"
Or When Button "'Stop', 27064 {stop sign icon}"
Remark "--- we'll stop listening to the line"
Set Variable * ll_done from Expression "true"
End When
End When
Until Expression "ll_done"
Delete Variable ll_done
First, we initialize the modem to make sure that it will give us a "RING" message when the phone rings. Since we don't want the modem to actually pick up and try to establish a connection, the S0=0 tells the modem not to answer the line.
The variable ll_done is our flag. It will tell us when we can exit our repeat loop.
In our repeat loop, we repeatedly look for three conditions.
First, we look to see if the user has clicked the "Stop" icon that we've placed on the icon bar. If so, we set the ll_done flag to true, which will get us out of the loop.
Second, we look to see if the user has hit the Escape key on the keyboard. If so, we set the ll_done flag to true, which will get us out of the loop.
Finally, we check to see if the message "RING" appears in the data stream from the modem. If it does, we wait a half second to allow the modem to send the carriage return that follows the "RING" message. Then, we call the "GetDate" script to get the current date and time. The "GetDate" script returns the current date and time in a variable called "GetDate", which we display on the screen. Then we look for one of two conditions, whether there is 10 seconds of silence on the serial port, or if the user has clicked the "Stop" icon that we've placed on the icon bar. We look for 10 seconds of silence because most callers will let the phone ring more than once, causing more than one RING message to appear on the screen. We don't want to report when each of these RING messages appear, just when the first one does. By waiting 10 seconds, we make sure that no more rings have occured during the call, and we are ready to wait for the next call.
After our repeat loop, we delete the ll_done variable, since we no longer need it.
Where to go from here
---------------------
There are many ways to go with LineListener. Maybe we'll investigate the possibilities in a future issue of Open Mike.
Important Note
--------------
Hacks are not guaranteed to work, although there is no reason why they shouldn't work. Every care has been taken to make sure that they work on the hacker's machine, but they may do other things on your machine. Of course, if you encounter problems, you may feel free to tweak the hack to run on your machine.